package com.hz.rouyigonggong.utils;

import java.io.Serializable;
/**
 * @description: TODO
     * @param
     * @return
     * @author: yzw
     * @date: 2025/3/5 9:04
 */

public class ResultJSON<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;
    // 默认构造函数
    public ResultJSON() {
    }
    public ResultJSON(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;

    }
    public static ResultJSON successORerror(int c){

        return  c>0? new ResultJSON(200,"操作成功",null):new ResultJSON(400,"操作失败",null);
    }

    public static <T> ResultJSON success(T data){
        return new ResultJSON(200,"操作成功",data);
    }
    public static <T> ResultJSON error(T data){
        return new ResultJSON(-1,"操作失败",data);
    }
    public static ResultJSON success(){
        return new ResultJSON(200,"操作成功",null);
    }
    public static ResultJSON success(Integer code,String msg){
        return new ResultJSON(code,msg,null);
    }
    public static ResultJSON error(){
        return new ResultJSON(400,"操作失败",null);
    }
    public static ResultJSON error(Integer code,String msg){
        return new ResultJSON(code,msg,null);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
    @Override
    public String toString() {
        return "ResultJSON{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
